package com.example.tse.rbyair.PKhome.adapter;

import android.content.Context;
import android.content.Intent;
import android.graphics.drawable.Drawable;
import android.text.Spannable;
import android.text.SpannableString;
import android.text.Spanned;
import android.text.style.AbsoluteSizeSpan;
import android.text.style.StrikethroughSpan;
import android.view.LayoutInflater;
import android.view.View;
import android.view.View.OnClickListener;
import android.view.ViewGroup;
import android.widget.BaseAdapter;
import android.widget.ImageView;
import android.widget.LinearLayout;
import android.widget.RelativeLayout;
import android.widget.RelativeLayout.LayoutParams;
import android.widget.TextView;

import com.example.tse.rbhttpservice.service.goods.model.GoodsGetSimilarListData;
import com.example.tse.rbyair.PKactivity.ProductDetialActivity;
import com.example.tse.rbyair.PKhome.model.MainVo;
import com.example.tse.rbyair.R;
import com.example.tse.rbyair.util.AppInforUtil;
import com.example.tse.rbyair.util.IntegrateConst;
import com.example.tse.rbyair.util.RbImageLoader;

import org.kymjs.kjframe.log.L;
import org.kymjs.kjframe.utils.DensityUtils;
import org.kymjs.kjframe.utils.StringUtils;

import java.util.ArrayList;
import java.util.List;

public class MainNewListAdapter extends BaseAdapter {
    private Context c;
    private LayoutInflater inflater;
    private int currentType = 0;
    private int SIMILAR = 1;
    private int HOLTSALE = 2;
    private int BANNER = 3;
    private int TITLE = 4;
    private int n;
    private int size = 0;
    private HolderClickListener mHolderClickListener;
    private List<GoodsGetSimilarListData> blockList;
    private List<MainVo> lists ;

    public MainNewListAdapter(Context c) {
        this.c = c;
        inflater = LayoutInflater.from(c);

        lists = new ArrayList<MainVo>();
    }

    public void setData(List<MainVo> lists, int size) {
        this.lists.clear();
        this.lists.addAll(lists);
        this.size = size;
        notifyDataSetChanged();
    }

    public void setNum(int n) {
        this.n = n;
    }

    @Override
    public int getCount() {
        return lists.size();
    }

    @Override
    public Object getItem(int position) {
        return null;
    }

    @Override
    public long getItemId(int position) {
        return position;
    }

    @Override
    public View getView(final int position, View convertView, ViewGroup parent) {
        final MainVo item = lists.get(position);
        View similarView = null;
        View holtsaleView = null;
        View bannerView = null;
        View titleView = null;

        SortSimilarViewHolder similarHolder;
        HoltSaleImgViewHolder bannerHolder;
        final HoltSaleViewHolder holtsaleHolder;

        currentType = getItemViewType(position);

        if (currentType == SIMILAR) {    //精选
            similarView = convertView;
            if (similarView == null) {
                similarView = inflater.inflate(R.layout.sortlistitem, null);
                similarHolder = new SortSimilarViewHolder();
                similarHolder.title = (TextView) similarView.findViewById(R.id.sortlist_item_title);
                similarHolder.iv1 = (ImageView) similarView.findViewById(R.id.sortlist_item_iv1);
                similarHolder.iv2 = (ImageView) similarView.findViewById(R.id.sortlist_item_iv2);
                similarHolder.iv3 = (ImageView) similarView.findViewById(R.id.sortlist_item_iv3);
                similarHolder.iv4 = (ImageView) similarView.findViewById(R.id.sortlist_item_iv4);
                similarHolder.iv5 = (ImageView) similarView.findViewById(R.id.sortlist_item_iv5);
                similarHolder.iv6 = (ImageView) similarView.findViewById(R.id.sortlist_item_iv6);

                similarHolder.tv3 = (TextView) similarView.findViewById(R.id.sortlist_item_name3);
                similarHolder.tv4 = (TextView) similarView.findViewById(R.id.sortlist_item_name4);
                similarHolder.tv5 = (TextView) similarView.findViewById(R.id.sortlist_item_name5);
                similarHolder.tv6 = (TextView) similarView.findViewById(R.id.sortlist_item_name6);

                similarHolder.lay1 = (LinearLayout) similarView.findViewById(R.id.sortlist_item_lay1);
                similarHolder.lay2 = (LinearLayout) similarView.findViewById(R.id.sortlist_item_lay2);
                similarHolder.lay3 = (LinearLayout) similarView.findViewById(R.id.sortlist_item_lay3);
                similarHolder.lay4 = (LinearLayout) similarView.findViewById(R.id.sortlist_item_lay4);
                int w = DensityUtils.getScreenW(c);

                LinearLayout.LayoutParams lp1 = new LinearLayout.LayoutParams(w, w * 7 / 25);
                similarHolder.iv1.setLayoutParams(lp1);

                LayoutParams lp2 = new LayoutParams(w * 2 / 5, w * 7 / 10);
                similarHolder.iv2.setLayoutParams(lp2);

                LayoutParams lp3 = (LayoutParams) similarHolder.lay1.getLayoutParams();
                lp3.width = w * 3 / 10;
                lp3.height = w * 7 / 20;

                LayoutParams lp4 = (LayoutParams) similarHolder.lay2.getLayoutParams();
                lp4.width = w * 3 / 10;
                lp4.height = w * 7 / 20;

                LayoutParams lp5 = (LayoutParams) similarHolder.lay3.getLayoutParams();
                lp5.width = w * 3 / 10;
                lp5.height = w * 7 / 20;

                LayoutParams lp6 = (LayoutParams) similarHolder.lay4.getLayoutParams();
                lp6.width = w * 3 / 10;
                lp6.height = w * 7 / 20;

                LinearLayout.LayoutParams lp7 = new LinearLayout.LayoutParams((w * 3 / 10) - DensityUtils.dip2px(c, 32), (w * 3 / 10) - DensityUtils.dip2px(c, 32));
                lp7.topMargin = DensityUtils.dip2px(c, 10);
                similarHolder.iv3.setLayoutParams(lp7);
                similarHolder.iv4.setLayoutParams(lp7);
                similarHolder.iv5.setLayoutParams(lp7);
                similarHolder.iv6.setLayoutParams(lp7);

                similarView.setTag(similarHolder);
            } else {
                similarHolder = (SortSimilarViewHolder) similarView.getTag();
            }

            similarHolder.title.setText(item.getSimilar().getName());
            Drawable drawable = c.getResources().getDrawable(R.drawable.classification_icon_excellent);
            drawable.setBounds(0, 0, drawable.getMinimumWidth(), drawable.getMinimumHeight());
            similarHolder.title.setCompoundDrawablePadding(DensityUtils.dip2px(c, 4));
            similarHolder.title.setCompoundDrawables(drawable, null, null, null);

            RbImageLoader.displayImage("", similarHolder.iv1, RbImageLoader.getLogoOptions());
            RbImageLoader.displayImage("", similarHolder.iv2);

            blockList = new ArrayList<GoodsGetSimilarListData>();
            similarHolder.iv1.setOnClickListener(null);
            similarHolder.iv2.setOnClickListener(null);

            for (GoodsGetSimilarListData gs : item.getSimilar().getData()) {
                if (gs.getImgType().equals("row")) {  //横图
                    RbImageLoader.displayImage(gs.getImg(), similarHolder.iv1, RbImageLoader.getLogoOptions());
                    similarHolder.iv1.setOnClickListener(new ClickListener(gs, position, 1));
                } else if (gs.getImgType().equals("col")) {  //树图
                    RbImageLoader.displayImage(gs.getImg(), similarHolder.iv2, RbImageLoader.getLogoOptions());
                    similarHolder.iv2.setOnClickListener(new ClickListener(gs, position, 2));
                } else if (gs.getImgType().equals("block")) {   //方块图
                    blockList.add(gs);
                } else {

                }
            }

            L.d("Rick", "position=" + position + "  blockList.size=" + blockList.size());

            if (blockList.size() == 4) {

                RbImageLoader.displayImage(blockList.get(0).getImg(), similarHolder.iv3, RbImageLoader.getProductDetialOptions());
                similarHolder.tv3.setText(blockList.get(0).getName());

                RbImageLoader.displayImage(blockList.get(1).getImg(), similarHolder.iv4, RbImageLoader.getProductDetialOptions());
                similarHolder.tv4.setText(blockList.get(1).getName());

                RbImageLoader.displayImage(blockList.get(2).getImg(), similarHolder.iv5, RbImageLoader.getProductDetialOptions());
                similarHolder.tv5.setText(blockList.get(2).getName());

                RbImageLoader.displayImage(blockList.get(3).getImg(), similarHolder.iv6, RbImageLoader.getProductDetialOptions());
                similarHolder.tv6.setText(blockList.get(3).getName());

                similarHolder.iv3.setOnClickListener(new ClickListener(blockList.get(0), position, 3));
                similarHolder.iv4.setOnClickListener(new ClickListener(blockList.get(1), position, 4));
                similarHolder.iv5.setOnClickListener(new ClickListener(blockList.get(2), position, 5));
                similarHolder.iv6.setOnClickListener(new ClickListener(blockList.get(3), position, 6));

            } else if (blockList.size() == 3) {
                RbImageLoader.displayImage(blockList.get(0).getImg(), similarHolder.iv3, RbImageLoader.getProductDetialOptions());
                similarHolder.tv3.setText(blockList.get(0).getName());

                RbImageLoader.displayImage(blockList.get(1).getImg(), similarHolder.iv4, RbImageLoader.getProductDetialOptions());
                similarHolder.tv4.setText(blockList.get(1).getName());

                RbImageLoader.displayImage(blockList.get(2).getImg(), similarHolder.iv5, RbImageLoader.getProductDetialOptions());
                similarHolder.tv5.setText(blockList.get(2).getName());

                RbImageLoader.displayImage("", similarHolder.iv6, RbImageLoader.getProductDetialOptions());
                similarHolder.tv6.setText("");

                similarHolder.iv3.setOnClickListener(new ClickListener(blockList.get(0), position, 3));
                similarHolder.iv4.setOnClickListener(new ClickListener(blockList.get(1), position, 4));
                similarHolder.iv5.setOnClickListener(new ClickListener(blockList.get(2), position, 5));
                similarHolder.iv6.setOnClickListener(null);

            } else if (blockList.size() == 2) {
                RbImageLoader.displayImage(blockList.get(0).getImg(), similarHolder.iv3, RbImageLoader.getProductDetialOptions());
                similarHolder.tv3.setText(blockList.get(0).getName());

                RbImageLoader.displayImage(blockList.get(1).getImg(), similarHolder.iv4, RbImageLoader.getProductDetialOptions());
                similarHolder.tv4.setText(blockList.get(1).getName());

                RbImageLoader.displayImage("", similarHolder.iv5, RbImageLoader.getProductDetialOptions());
                similarHolder.tv5.setText("");
                RbImageLoader.displayImage("", similarHolder.iv6, RbImageLoader.getProductDetialOptions());
                similarHolder.tv6.setText("");

                similarHolder.iv3.setOnClickListener(new ClickListener(blockList.get(0), position, 3));
                similarHolder.iv4.setOnClickListener(new ClickListener(blockList.get(1), position, 4));
                similarHolder.iv5.setOnClickListener(null);
                similarHolder.iv6.setOnClickListener(null);

            } else if (blockList.size() == 1) {
                RbImageLoader.displayImage(blockList.get(0).getImg(), similarHolder.iv3, RbImageLoader.getProductDetialOptions());
                similarHolder.tv3.setText(blockList.get(0).getName());

                RbImageLoader.displayImage("", similarHolder.iv4, RbImageLoader.getProductDetialOptions());
                similarHolder.tv4.setText("");
                RbImageLoader.displayImage("", similarHolder.iv5, RbImageLoader.getProductDetialOptions());
                similarHolder.tv5.setText("");
                RbImageLoader.displayImage("", similarHolder.iv6, RbImageLoader.getProductDetialOptions());
                similarHolder.tv6.setText("");

                similarHolder.iv3.setOnClickListener(new ClickListener(blockList.get(0), position, 3));
                similarHolder.iv4.setOnClickListener(null);
                similarHolder.iv5.setOnClickListener(null);
                similarHolder.iv6.setOnClickListener(null);
            } else if (blockList.size() == 0) {
                RbImageLoader.displayImage("", similarHolder.iv3, RbImageLoader.getProductDetialOptions());
                similarHolder.tv3.setText("");
                RbImageLoader.displayImage("", similarHolder.iv4, RbImageLoader.getProductDetialOptions());
                similarHolder.tv4.setText("");
                RbImageLoader.displayImage("", similarHolder.iv5, RbImageLoader.getProductDetialOptions());
                similarHolder.tv5.setText("");
                RbImageLoader.displayImage("", similarHolder.iv6, RbImageLoader.getProductDetialOptions());
                similarHolder.tv6.setText("");

                similarHolder.iv3.setOnClickListener(null);
                similarHolder.iv4.setOnClickListener(null);
                similarHolder.iv5.setOnClickListener(null);
                similarHolder.iv6.setOnClickListener(null);
            }
            convertView = similarView;
        } else if (currentType == HOLTSALE) {  //热卖推荐
            holtsaleView = convertView;
            if (holtsaleView == null) {
                holtsaleView = inflater.inflate(R.layout.mainholtsaleitem, null);
                holtsaleHolder = new HoltSaleViewHolder();
                holtsaleHolder.holtsale_relay = (RelativeLayout) holtsaleView.findViewById(R.id.holtsale_relay);
                holtsaleHolder.mainiv = (ImageView) holtsaleView.findViewById(R.id.holtsale_iv);
                holtsaleHolder.countryiv = (ImageView) holtsaleView.findViewById(R.id.holtsale_countryiv);
                holtsaleHolder.joinNum = (TextView) holtsaleView.findViewById(R.id.holtsale_joinNum);
                holtsaleHolder.price = (TextView) holtsaleView.findViewById(R.id.holtsale_price);
                holtsaleHolder.mktprice = (TextView) holtsaleView.findViewById(R.id.holtsale_mktprice);
                holtsaleHolder.shoppingcartiv = (ImageView) holtsaleView.findViewById(R.id.shoppingcart_iv);
                holtsaleHolder.name = (TextView) holtsaleView.findViewById(R.id.holtsale_name);
                holtsaleHolder.content = (TextView) holtsaleView.findViewById(R.id.holtsale_content);
                holtsaleHolder.noStorebg = (ImageView) holtsaleView.findViewById(R.id.noStorebg);
                int w = DensityUtils.getScreenW(c);
                LayoutParams lp = new LayoutParams(w, w * 61 / 100);
                holtsaleHolder.mainiv.setLayoutParams(lp);

                holtsaleView.setTag(holtsaleHolder);
            } else {
                holtsaleHolder = (HoltSaleViewHolder) holtsaleView.getTag();
            }

            RbImageLoader.displayImage(item.getHoltsale_goods().getImageHotSales(), DensityUtils.dip2px(c, 5), holtsaleHolder.mainiv);
            RbImageLoader.displayImage(item.getHoltsale_goods().getImageCountry(), holtsaleHolder.countryiv, null);
            holtsaleHolder.joinNum.setText(item.getHoltsale_goods().getJoinNum() + "人参与");


            if (item.getHoltsale_goods().getPrice() != null) {
                String s = "￥" + StringUtils.formatPrice3(item.getHoltsale_goods().getPrice());
                Spannable WordtoSpan = new SpannableString(s);
                WordtoSpan.setSpan(new AbsoluteSizeSpan(DensityUtils.dip2px(c, 12)), 0, 1, Spannable.SPAN_EXCLUSIVE_EXCLUSIVE);
                WordtoSpan.setSpan(new AbsoluteSizeSpan(DensityUtils.dip2px(c, 20)), 1, s.length(), Spannable.SPAN_EXCLUSIVE_EXCLUSIVE);
                holtsaleHolder.price.setText(WordtoSpan);
            }

            if (item.getHoltsale_goods().getMktprice() != null) {
                String mktprice = StringUtils.formatPrice3(item.getHoltsale_goods().getMktprice());
                SpannableString sp = new SpannableString("￥" + mktprice);
                sp.setSpan(new StrikethroughSpan(), 0, mktprice.length() + 1, Spanned.SPAN_EXCLUSIVE_EXCLUSIVE);
                holtsaleHolder.mktprice.setText(sp);
            }

            holtsaleHolder.name.setText(item.getHoltsale_goods().getName());
            holtsaleHolder.content.setText(item.getHoltsale_goods().getBrief());

            holtsaleHolder.holtsale_relay.setOnClickListener(new OnClickListener() {

                @Override
                public void onClick(View arg0) {

                    // TODO 统计
//					Intent intent = new Intent(c, ProductDetialActivity2.class);
//					intent.putExtra("productId", item.getHoltsale_goods().getProductId());
//					intent.putExtra("rudder_position", IntegrateConst.HOT_POSITION + item.getPosition());
//					intent.putExtra("rudder_route", IntegrateConst.NEW_SORT_ROUTE);
//					c.startActivity(intent);
                }
            });

//			holtsaleHolder.shoppingcartiv.setOnClickListener(new OnClickListener() {
//
//                @Override
//                public void onClick(View arg0) {
//
//                    GoodsGetRequest r = new GoodsGetRequest();
//                    r.setProductId(item.getHoltsale_goods().getProductId());
//                    r.setIsFastBuy("0");
//                    r.setType("0");
//                    r.setDeviceId(AppInforUtil.getDeviceId(c));
//
//                    RemoteServiceFactory.getInstance().getGoodsService(c).get(r, new RemoteServiceListener<GoodsGetResponse>() {
//
//                        @Override
//                        public void ok(GoodsGetResponse t) {
//
//                            if (SharedPreferenceUtils.getValueByKey(c, "memberId").equals("") || SharedPreferenceUtils.getValueByKey(c, "memberId").isEmpty()) {
//                                Toast.makeText(c, "请先登录", 0).show();
//                                Intent intent = new Intent(c, LoginActivity.class);
//                                intent.putExtra("type", "1");
//                                c.startActivity(intent);
//                                return;
//                            } else if (t.getQuantity().equals("0")) {
//                                holtsaleHolder.noStorebg.setVisibility(0);
//                                Toast.makeText(c, "好东西被抢光了，正在备货中", 0).show();
//                            } else {
//                                holtsaleHolder.noStorebg.setVisibility(8);
//                            }
//
//
//                            boolean selecteable = false;
//                            a:
//                            for (GoodsGetSpecs ggs : t.getSpecs()) {
//                                if (ggs.getSpecValues().size() > 1) {
//                                    selecteable = true;
//                                    break a;
//                                }
//                            }
//
//                            if (selecteable) {  //有规格 并且有可选择性
//                                MainActivity baseActivity = (MainActivity) c;
//                                AddShopCartDialog addShopCartDialog = new AddShopCartDialog(t, position);
//                                addShopCartDialog.show(baseActivity.getSupportFragmentManager(), "");
//                                addShopCartDialog.setOnMutiplTagClickedListener(new OnMutiplTagClickedListener() {
//
//                                    @Override
//                                    public void OnClicked() {
//                                        if (mHolderClickListener != null) {
//                                            int[] start_location = new int[2];
//
//                                            holtsaleHolder.mainiv.getLocationInWindow(start_location);//获取点击商品图片的位置
//                                            Drawable drawable = holtsaleHolder.mainiv.getDrawable();//复制一个新的商品图标
//                                            mHolderClickListener.onHolderClick(drawable, start_location);
//                                        }
//                                    }
//                                });
//
//                            } else {   //没有规格
//                                L.d("hp", "MainNewListAdapter position:" + position);
//                                addToShopCart(holtsaleHolder.mainiv, t.getProductId(), t.getGoodsId(), 1, position);
//                            }
//                        }
//
//                        @Override
//                        public void failue(int errorCode, String errorMessage) {
//
//                        }
//                    });
//                }
//            });
            if (lists.get(position).getHoltsale_goods().getStoreNum().equals("0")) { // 库存0
                holtsaleHolder.noStorebg.setVisibility(View.VISIBLE);
            } else {
                holtsaleHolder.noStorebg.setVisibility(View.GONE);
            }
            LayoutParams lp1 = new LayoutParams(LayoutParams.MATCH_PARENT, LayoutParams.MATCH_PARENT);
            lp1.setMargins(0, 170, 0, 0);
            holtsaleHolder.noStorebg.setLayoutParams(lp1);

            convertView = holtsaleView;
        } else if (currentType == BANNER) {    //banner
            bannerView = convertView;
            if (bannerView == null) {
                bannerView = inflater.inflate(R.layout.image_item, null);
                bannerHolder = new HoltSaleImgViewHolder();
                bannerHolder.iv = (ImageView) bannerView.findViewById(R.id.iv);
                int w = DensityUtils.getScreenW(c) - DensityUtils.dip2px(c, 16);
                LinearLayout.LayoutParams lp = new LinearLayout.LayoutParams(w, w * 7 / 20);
                lp.leftMargin = DensityUtils.dip2px(c, 8);
                lp.rightMargin = DensityUtils.dip2px(c, 8);
                bannerHolder.iv.setLayoutParams(lp);

                bannerView.setTag(bannerHolder);
            } else {
                bannerHolder = (HoltSaleImgViewHolder) bannerView.getTag();
            }

            RbImageLoader.displayImage(item.getHoltsale_banner().getUrl(), DensityUtils.dip2px(c, 5), bannerHolder.iv);
            bannerHolder.iv.setOnClickListener(new OnClickListener() {
                @Override
                public void onClick(View arg0) {
                    L.i("banner  item.getPosition()=" + item.getPosition());
                    // TODO 统计
                    String type = item.getHoltsale_banner().getLinkType();
//					if(type.equals("h5link")){
//						Intent intentWeb = new Intent(c, WebViewDetail.class);
////						intentWeb.putExtra("target", item.getHoltsale_banner().getLink());
//						if (item.getHoltsale_banner().getLink().contains("?")) {
//							intentWeb.putExtra("target", item.getHoltsale_banner().getLink() + "&rudder_position=" + IntegrateConst.HOT_BANNER_POSITION + (item.getPosition()) + "&rudder_route=" + IntegrateConst.NEW_SORT_ROUTE
//									+ "&rudder_appType=" + "android" + "&rudder_market=" + AppInforUtil.market + "&rudder_deviceId=" + AppInforUtil.getDeviceId(c)
//									+ "&rudder_deviceInfo=" + AppInforUtil.getInfo(c)
//									+ "&rudder_activityId=" + AppInforUtil.getInstance().getActivityId());
//						} else {
//							intentWeb.putExtra("target", item.getHoltsale_banner().getLink() + "?rudder_position=" + IntegrateConst.HOT_BANNER_POSITION + (item.getPosition()) + "&rudder_route=" + IntegrateConst.NEW_SORT_ROUTE
//									+ "&rudder_appType=" + "android" + "&rudder_market=" + AppInforUtil.market + "&rudder_deviceId=" + AppInforUtil.getDeviceId(c)
//									+ "&rudder_deviceInfo=" + AppInforUtil.getInfo(c)
//									+ "&rudder_activityId=" + AppInforUtil.getInstance().getActivityId());
//						}
//						c.startActivity(intentWeb);
//					}else if(type.equals("goods")){
//						Intent intentGoods = new Intent(c, ProductDetialActivity2.class);
//						intentGoods.putExtra("productId", item.getHoltsale_goods().getProductId());
//						intentGoods.putExtra("rudder_position", IntegrateConst.HOT_BANNER_POSITION + (item.getPosition()));
//						intentGoods.putExtra("rudder_route", IntegrateConst.NEW_SORT_ROUTE);
//						intentGoods.putExtra("productId", item.getHoltsale_banner().getLink());
//						c.startActivity(intentGoods);
//					}else if(type.equals("special")){
//						Intent i = new Intent(c, SortSpecialActivity.class);
//						i.putExtra("rudder_position", IntegrateConst.HOT_BANNER_POSITION + (item.getPosition()));
//						i.putExtra("rudder_route", IntegrateConst.NEW_SORT_ROUTE);
//						i.putExtra("similarId", item.getHoltsale_banner().getLink());
//						c.startActivity(i);
//					}else{
//						return;
//					}
                }
            });

            convertView = bannerView;
        } else {   //热卖推荐  标题
            titleView = convertView;
            titleView = inflater.inflate(R.layout.holtsaletitle, null);
            convertView = titleView;
        }

        return convertView;
    }

    @Override
    public int getViewTypeCount() {
        return 5;
    }

    @Override
    public int getItemViewType(int position) {
        if (lists.get(position).getType().equals("similar")) {
            return SIMILAR;
        } else if (lists.get(position).getType().equals("holtsale_goods")) {
            return HOLTSALE;
        } else if (lists.get(position).getType().equals("holtsale_title")) {
            return TITLE;
        } else {
            return BANNER;
        }
    }

    private void addToShopCart(final ImageView iv, String productId, String goodsId, int count, int position) {
//		ShoppingAddRequest r = new ShoppingAddRequest();
//		r.setProductId(productId);
//		r.setGoodsId(goodsId);
//		r.setIsFastBuy("0");
//		r.setQuantity(""+count);
//		//		r.setRudder_position(rudder_position);
//		r.setLimit("");
//		r.setType("0");
//		//		r.setSecondId(secondId);
//		r.setTargetId("");
//		r.setRudder_route(IntegrateConst.NEW_SORT_ROUTE + "|"+ IntegrateConst.HOT_POSITION + (position+1));
//
//		RemoteServiceFactory.getInstance().getShoppingService(c).add(r, new RemoteServiceListener<ShoppingAddResponse>() {
//
//			@Override
//			public void ok(ShoppingAddResponse t) {
//
//				new Handler().postDelayed(new Runnable() {
//					public void run() {
//						EventBus.getDefault().post(new ShopCartNumEvent("add"));
//						Toast toast = Toast.makeText(c, "添加购物车成功", Toast.LENGTH_SHORT);
//						toast.setGravity(Gravity.CENTER, 0, 0);
//						toast.show();
//					}
//				}, 1000);
//
//				if(mHolderClickListener!=null){
//					int[] start_location = new int[2];
//					iv.getLocationInWindow(start_location);//获取点击商品图片的位置
//					Drawable drawable = iv.getDrawable();//复制一个新的商品图标
//					mHolderClickListener.onHolderClick(drawable,start_location);
//				}
//
//			}
//
//			@Override
//			public void failue(int errorCode, String errorMessage) {
//				//				Toast toast = Toast.makeText(c, errorMessage, Toast.LENGTH_SHORT);
//				//				toast.setGravity(Gravity.CENTER, 0, 0);
//				//				toast.show();
//			}
//		});
    }

    class ClickListener implements OnClickListener {
        GoodsGetSimilarListData gs;
        private int pos;
        private int i;

        public ClickListener(GoodsGetSimilarListData gs, int pos, int i) {
            this.gs = gs;
            this.pos = pos - n;
            this.i = i;
        }

        @Override
        public void onClick(View v) {
			if(gs.getLink().equals("") && gs.getLinkType().equals("other")){
//				Intent intent = new Intent(c, SortSpecialActivity.class);
//
//				if (gs.getImgType().equals("row") || i == 1) {
//					intent.putExtra("rudder_position", "FA_" + (pos+3) + "_1");
//					intent.putExtra("rudder_route", IntegrateConst.NEW_SORT_ROUTE);
//				}else if (gs.getImgType().equals("col") || i == 2) {
//					intent.putExtra("rudder_position", "FA_" + (pos+3) + "_2");
//					intent.putExtra("rudder_route", IntegrateConst.NEW_SORT_ROUTE);
//				}else if (i == 3) {
//					intent.putExtra("rudder_position", "FA_" + (pos+3) + "_3");
//					intent.putExtra("rudder_route", IntegrateConst.NEW_SORT_ROUTE);
//				}else if (i == 4) {
//					intent.putExtra("rudder_position", "FA_" + (pos+3) + "_4");
//					intent.putExtra("rudder_route", IntegrateConst.NEW_SORT_ROUTE);
//				}else if (i == 5) {
//					intent.putExtra("rudder_position", "FA_" + (pos+3) + "_5");
//					intent.putExtra("rudder_route", IntegrateConst.NEW_SORT_ROUTE);
//				}else if (i == 6) {
//					intent.putExtra("rudder_position", "FA_" + (pos+3) + "_6");
//					intent.putExtra("rudder_route", IntegrateConst.NEW_SORT_ROUTE);
//				}
//
//				//					intent.putExtra("rudder_route", IntegrateConst.NEW_SELECT_ROUTE_ROOT + (position+3));
//				//					intent.putExtra("rudder_position", "FA_" + (position+3) + "_1");
//				intent.putExtra("similarId", gs.getSimilarId());
//				c.startActivity(intent);
			}else if(!gs.getLink().equals("") && gs.getLinkType().equals("goods")){
				Intent intent = new Intent(c, ProductDetialActivity.class);
				if (gs.getImgType().equals("row")) {
					intent.putExtra("rudder_position", "FA_" + (pos+3) + "_1");
					intent.putExtra("rudder_route", IntegrateConst.NEW_SORT_ROUTE);
				}else if (gs.getImgType().equals("col")) {
					intent.putExtra("rudder_position", "FA_" + (pos+3) + "_2");
					intent.putExtra("rudder_route", IntegrateConst.NEW_SORT_ROUTE);
				}else if (i == 3) {
					intent.putExtra("rudder_position", "FA_" + (pos+3) + "_3");
					intent.putExtra("rudder_route", IntegrateConst.NEW_SORT_ROUTE);
				}else if (i == 4) {
					intent.putExtra("rudder_position", "FA_" + (pos+3) + "_4");
					intent.putExtra("rudder_route", IntegrateConst.NEW_SORT_ROUTE);
				}else if (i == 5) {
					intent.putExtra("rudder_position", "FA_" + (pos+3) + "_5");
					intent.putExtra("rudder_route", IntegrateConst.NEW_SORT_ROUTE);
				}else if (i == 6) {
					intent.putExtra("rudder_position", "FA_" + (pos+3) + "_6");
					intent.putExtra("rudder_route", IntegrateConst.NEW_SORT_ROUTE);
				}
				intent.putExtra("productId", gs.getLink());
				c.startActivity(intent);
			}else if(!gs.getLink().equals("") && gs.getLinkType().equals("h5link")){
//				Intent intent = new Intent(c, WebViewDetail.class);
//				intent.putExtra("target", statisticsManger(gs,i));
//				c.startActivity(intent);
			}else if(!gs.getLink().equals("") && gs.getLinkType().equals("other")){
//				Intent intent = new Intent(c, SortSpecialActivity.class);
//				if (gs.getImgType().equals("row") || i == 1) {
//					intent.putExtra("rudder_position", "FA_" + (pos+3) + "_1");
//					intent.putExtra("rudder_route", IntegrateConst.NEW_SORT_ROUTE);
//				}else if (gs.getImgType().equals("col") || i == 2) {
//					intent.putExtra("rudder_position", "FA_" + (pos+3) + "_2");
//					intent.putExtra("rudder_route", IntegrateConst.NEW_SORT_ROUTE);
//				}else if (i == 3) {
//					intent.putExtra("rudder_position", "FA_" + (pos+3) + "_3");
//					intent.putExtra("rudder_route", IntegrateConst.NEW_SORT_ROUTE);
//				}else if (i == 4) {
//					intent.putExtra("rudder_position", "FA_" + (pos+3) + "_4");
//					intent.putExtra("rudder_route", IntegrateConst.NEW_SORT_ROUTE);
//				}else if (i == 5) {
//					intent.putExtra("rudder_position", "FA_" + (pos+3) + "_5");
//					intent.putExtra("rudder_route", IntegrateConst.NEW_SORT_ROUTE);
//				}else if (i == 6) {
//					intent.putExtra("rudder_position", "FA_" + (pos+3) + "_6");
//					intent.putExtra("rudder_route", IntegrateConst.NEW_SORT_ROUTE);
//				}
//				intent.putExtra("similarId", gs.getSimilarId());
//				c.startActivity(intent);
			}
			else if(gs.getLink().equals("") && gs.getLinkType().equals("img")){

			}
        }
    }

    private String statisticsManger(GoodsGetSimilarListData gs, int j) {

        String position = "";
        String rute = "";

        if (gs.getImgType().equals("row")) {
            position = "FA_" + (position + 3) + "_1";
            rute = IntegrateConst.NEW_SORT_ROUTE;
        } else if (gs.getImgType().equals("col")) {
            position = "FA_" + (position + 3) + "_2";
            rute = IntegrateConst.NEW_SORT_ROUTE;
        } else if (j == 3) {
            position = "FA_" + (position + 3) + "_3";
            rute = IntegrateConst.NEW_SORT_ROUTE;
        } else if (j == 4) {
            position = "FA_" + (position + 3) + "_4";
            rute = IntegrateConst.NEW_SORT_ROUTE;
        } else if (j == 5) {
            position = "FA_" + (position + 3) + "_5";
            rute = IntegrateConst.NEW_SORT_ROUTE;
        } else if (j == 6) {
            position = "FA_" + (position + 3) + "_6";
            rute = IntegrateConst.NEW_SORT_ROUTE;
        }

        if (gs.getLink().contains("?")) {
            return gs.getLink() + "&rudder_position=" + position + "&rudder_route=" + rute
                    + "&rudder_appType=" + "android" + "&rudder_market=" + AppInforUtil.market + "&rudder_deviceId=" + AppInforUtil.getDeviceId(c)
                    + "&rudder_deviceInfo=" + AppInforUtil.getInfo(c)
                    + "&rudder_activityId=" + AppInforUtil.getInstance().getActivityId();
        } else {
            return gs.getLink() + "?rudder_position=" + position + "&rudder_route=" + rute
                    + "&rudder_appType=" + "android" + "&rudder_market=" + AppInforUtil.market + "&rudder_deviceId=" + AppInforUtil.getDeviceId(c)
                    + "&rudder_deviceInfo=" + AppInforUtil.getInfo(c)
                    + "&rudder_activityId=" + AppInforUtil.getInstance().getActivityId();
        }
    }

    class SortSimilarViewHolder {
        LinearLayout lay1;
        LinearLayout lay2;
        LinearLayout lay3;
        LinearLayout lay4;
        TextView title;
        ImageView iv1;
        ImageView iv2;

        ImageView iv3;
        TextView tv3;
        ImageView iv4;
        TextView tv4;
        ImageView iv5;
        TextView tv5;
        ImageView iv6;
        TextView tv6;
    }

    class HoltSaleViewHolder {
        RelativeLayout holtsale_relay;
        ImageView noStorebg;
        ImageView mainiv;
        ImageView countryiv;
        TextView joinNum;
        TextView price;
        TextView mktprice;
        ImageView shoppingcartiv;
        TextView name;
        TextView content;
    }

    class HoltSaleImgViewHolder {
        ImageView iv;
    }

    public void SetOnSetHolderClickListener(HolderClickListener holderClickListener) {
        this.mHolderClickListener = holderClickListener;
    }

    public interface HolderClickListener {
        public void onHolderClick(Drawable drawable, int[] start_location);
    }
}
